package leetcode.D100.T26;

class Solution {
    // 一刷
    /*public int removeDuplicates(int[] nums) {
        int i = 0, j = 0;
        while(true) {
            while(j < nums.length && nums[i] == nums[j]) {
                ++j;
            }
            if(j >= nums.length) break;
            nums[++i] = nums[j];
        }
        return i+1;
    }*/

    // 二刷
    public int removeDuplicates(int[] nums) {
        if (nums.length == 0)
            return 0;
        int i = 0, j = 1;
        while(j < nums.length) {
            if (nums[j] != nums[i]) {
                nums[++i] = nums[j];
            }
            ++j;
        }
        return i + 1;
    }
}